<?php
class TaskModel{
    public function getTasks($page, $per_page=10) {
        $from = $page*$per_page;
        $query = mysql_query("SELECT * FROM task ORDER by created ASC LIMIT ".$from.",".$per_page);
        $res = array();
        while ($row = mysql_fetch_array($query)) {
            $res[] = $row;
        }
        return $res;
    }
    public function getTask($id) {
        $query = mysql_query("SELECT * FROM task as t1
                              LEFT JOIN task_extended as t2
                              ON t1.id_task = t2.id_task
                              WHERE t1.id_task = ".$id);
        return ($query?mysql_fetch_array($query):false);
    }
    
    public function hasTaskInBase($id) {
        $query = mysql_query("SELECT COUNT(*) FROM task WHERE id_task=" . $id . "");
        if (mysql_result($query, 0) > 0)
            return TRUE;
        else
            return FALSE;
    }
    
}
?>
